/*------------------------------------------------------
                hou_elearningGEN beta v1.0
Author: xtrung.net@gmail.com
Write On: 04/27/2008
Create On:4/13/2012 11:22:16 AM
------------------------------------------------------*/
using hou_elearning.Entity;
using hou_elearning.DataAccess;
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Text;
namespace hou_elearning.Business
{
    public class Nhomnguoidung_QuyenBRL
    {
        #region Init
        private static string EX_NOT_EXIST="Không Tồn Tại Nhomnguoidung_Quyen Này";
		private static string EX_FK_INHOMNGUOIDUNGID_INVALID="FK_iNhomnguoidungID không hợp lệ";
		private static string EX_FK_IMAQUYENID_INVALID="FK_iMaquyenID không hợp lệ";
		private static string EX_ID_INVALID="FK_iNhomnguoidungID không hợp lệ";
        #endregion
        #region Public Methods
        /// <summary>
        /// Get Nhomnguoidung_Quyen Theo ID
        /// </summary>
        /// <param name="FK_iNhomnguoidungID">Int16:Nhomnguoidung_Quyen ID</param>
        /// <returns>Nhomnguoidung_QuyenEntity</returns>        
        public static Nhomnguoidung_QuyenEntity GetOne(Int16 FK_iNhomnguoidungID)
        {
            
			if(FK_iNhomnguoidungID<=0)
				throw new Exception(EX_ID_INVALID);
            return Nhomnguoidung_QuyenDAL.GetOne(FK_iNhomnguoidungID);
        }
        /// <summary>
        /// Lấy về List các Nhomnguoidung_Quyen
        /// </summary>
        /// <returns>List Nhomnguoidung_QuyenEntity:List Nhomnguoidung_Quyen Cần lấy</returns>
        public static List<Nhomnguoidung_QuyenEntity> GetAll()
        {
            return Nhomnguoidung_QuyenDAL.GetAll();
        }
        
        /// <summary>
        /// Kiểm tra và thêm mới Nhomnguoidung_Quyen
        /// </summary>
        /// <param name="entity">Entity</param>
        /// <returns>Int32: ID của Nhomnguoidung_Quyen Mới Thêm Vào</returns>
        public static Int32 Add(Nhomnguoidung_QuyenEntity entity)
        {
            checkLogic(entity);
            checkDuplicate(entity, false);
            checkFK(entity);
            return Nhomnguoidung_QuyenDAL.Add(entity);
        }
        /// <summary>
        /// Kiểm tra và chỉnh sửa Nhomnguoidung_Quyen
        /// </summary>
        /// <param name="entity">Nhomnguoidung_QuyenEntity</param>
        /// <returns>bool:kết quả thực hiện</returns>
        public static bool Edit(Nhomnguoidung_QuyenEntity entity)
        {
            checkExist(entity.FK_iNhomnguoidungID);
            checkLogic(entity);
            checkDuplicate(entity, true);
            checkFK(entity);
            return Nhomnguoidung_QuyenDAL.Edit(entity);
        }
        /// <summary>
        /// Kiểm tra và xoá Nhomnguoidung_Quyen
        /// </summary>
        /// <param name="FK_iNhomnguoidungID">Int16 : FK_iNhomnguoidungID</param>
        /// <returns>bool:kết quả thực hiện</returns>
        public static bool Remove(Int16 FK_iNhomnguoidungID)
        {
            checkExist(FK_iNhomnguoidungID);
            return Nhomnguoidung_QuyenDAL.Remove(FK_iNhomnguoidungID);
        }
        #endregion
        #region Private Methods
        private static void checkExist(Int16 FK_iNhomnguoidungID)
        {
            Nhomnguoidung_QuyenEntity oNhomnguoidung_Quyen=Nhomnguoidung_QuyenDAL.GetOne(FK_iNhomnguoidungID);
            if(oNhomnguoidung_Quyen==null)
                throw new Exception(EX_NOT_EXIST);
        }
        /// <summary>
        /// Kiểm tra logic Entity
        /// </summary>
        /// <param name="entity">Nhomnguoidung_QuyenEntity: entity</param>
        private static void checkLogic(Nhomnguoidung_QuyenEntity entity)
        {   
			if (entity.FK_iNhomnguoidungID < 0)
				throw new Exception(EX_FK_INHOMNGUOIDUNGID_INVALID);
			if (entity.FK_iMaquyenID < 0)
				throw new Exception(EX_FK_IMAQUYENID_INVALID);
        }
        /// <summary>
        /// Kiểm tra trùng lặp bản ghi
        /// </summary>
        /// <param name="entity">Nhomnguoidung_QuyenEntity: Nhomnguoidung_QuyenEntity</param>
        private static void checkDuplicate(Nhomnguoidung_QuyenEntity entity,bool checkPK)
        {
            /* 
            Example
            List<Nhomnguoidung_QuyenEntity> list = Nhomnguoidung_QuyenDAL.GetAll();
            if (list.Exists(
                delegate(Nhomnguoidung_QuyenEntity oldEntity)
                {
                    bool result =oldEntity.FIELD.Equals(entity.FIELD, StringComparison.OrdinalIgnoreCase);
                    if(checkPK)
                        result=result && oldEntity.FK_iNhomnguoidungID != entity.FK_iNhomnguoidungID;
                    return result;
                }
            ))
            {
                list.Clear();
                throw new Exception(EX_FIELD_EXISTED);
            }
            */
        }
        /// <summary>
        /// Kiểm tra tồn tại khóa ngoại
        /// </summary>
        /// <param name="entity">Nhomnguoidung_QuyenEntity:entity</param>
        private static void checkFK(Nhomnguoidung_QuyenEntity entity)
        {            
        }
        #endregion
    }
}
